package com.ruoyi.web.controller.pill;

import com.pill.system.domain.PillFactory;
import com.pill.system.service.IPillFactoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 【请填写功能名称】Controller
 * 
 * @author zhd
 * @date 2023-11-07
 */
@RestController
@RequestMapping("/system/factory")
public class PillFactoryController extends BaseController
{
    @Autowired(required = false)
    private IPillFactoryService pillFactoryService;

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(PillFactory pillFactory)
    {
        startPage();
        List<PillFactory> list = pillFactoryService.selectPillFactoryList(pillFactory);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:factory:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PillFactory pillFactory)
    {
        List<PillFactory> list = pillFactoryService.selectPillFactoryList(pillFactory);
        ExcelUtil<PillFactory> util = new ExcelUtil<PillFactory>(PillFactory.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:factory:query')")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable("factoryId") Long factoryId)
    {
        return success(pillFactoryService.selectPillFactoryByFactoryId(factoryId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:factory:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PillFactory pillFactory)
    {
        return toAjax(pillFactoryService.insertPillFactory(pillFactory));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:factory:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PillFactory pillFactory)
    {
        return toAjax(pillFactoryService.updatePillFactory(pillFactory));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:factory:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Long[] factoryIds)
    {
        return toAjax(pillFactoryService.deletePillFactoryByFactoryIds(factoryIds));
    }

    public static void main(String[] args) {
        UUID uuid = UUID.randomUUID();
//        ArrayList<String> list = new ArrayList<>();
//        list.add("123");
//        Object[] objects = list.toArray();
//        for (int i = 0; i < objects.length; i++) {
//            System.out.println(objects[0]);
//        }
//        String[] arr = {"113","sasa"};
//        ArrayList<String> list = new ArrayList<>(Arrays.asList(arr));
//        list.add("dsds");
//        list.stream().forEach(System.out::println);

//        int[] array ={17258, 39322, 17258, 39322, 17258, 52429, 17355, 9830, 17355, 16384};
//        List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
//        list.stream().distinct().collect(Collectors.toList()).forEach(System.out::println);
//        System.out.println("------------------");
//        list.forEach(System.out::println);
//        list.stream().filter(t->!String.valueOf(t).equals("17258")).forEach(System.out::println);

        ArrayList<Person> people = new ArrayList<>();
        people.add(new Person("tom",22));
        people.add(new Person("admin",19));
        people.add(new Person("xiaozhao",9));
        List<String> stringList = people.stream().filter(t -> t.getSalary() > 20).map(Person::toString).collect(Collectors.toList());
        stringList.forEach(System.out::println);


    }
}
